package com.tracybai.microblogging.blogoauth;


import java.util.HashMap;


public class SinaOAuthService extends OAuthService {

	public SinaOAuthService(String consumerKey, String consumerSecret) {
		super(consumerKey,consumerSecret);
	}
	public OAuthToken getRequestToken(){
		mOAuthRequest = new SinaOAuthRequest("POST", "http://api.t.sina.com.cn/oauth/request_token");
		mOAuthRequest.addBodyParam("oauth_callback", URL_ACTIVITY_CALLBACK);
		mOAuthRequest.addOAuthParam("oauth_timestamp", getTimestampInSeconds());
		mOAuthRequest.addOAuthParam("oauth_nonce", getNonce());
		mOAuthRequest.addOAuthParam("oauth_consumer_key", mConsumerKey);
		mOAuthRequest.addOAuthParam("oauth_signature_method", "HMAC-SHA1");
		mOAuthRequest.addOAuthParam("oauth_version", "1.0");
	    OAuthToken oAuthToken = OAuthConstants.EMPTY_TOKEN;
	    String str5 = getSignature(mOAuthRequest, oAuthToken);
	    mOAuthRequest.addOAuthParam("oauth_signature", str5);
	    return mOAuthRequest.getToken();
	  }
	@Override
	public OAuthToken getAccessToken(OAuthToken oAuthToken, String verifier) {
		mOAuthRequest = new SinaOAuthRequest("POST", "http://api.t.sina.com.cn/oauth/access_token");
		mOAuthRequest.addBodyParam("oauth_verifier", verifier);
		mOAuthRequest.addOAuthParam("oauth_timestamp", getTimestampInSeconds());
		mOAuthRequest.addOAuthParam("oauth_nonce", getNonce());
		mOAuthRequest.addOAuthParam("oauth_consumer_key", mConsumerKey);
		mOAuthRequest.addOAuthParam("oauth_signature_method", "HMAC-SHA1");
		mOAuthRequest.addOAuthParam("oauth_version", "1.0");
	    mOAuthRequest.addOAuthParam("oauth_token", oAuthToken.getToken());
	    String str6 = getSignature(mOAuthRequest, oAuthToken);
	    mOAuthRequest.addOAuthParam("oauth_signature", str6);
	    return mOAuthRequest.getAccessToken();
	}
	
	
	@Override
	public String pushMsg(HashMap<String,String> params, OAuthToken oAuthToken){
		mOAuthRequest = new SinaOAuthRequest("POST", "http://api.t.sina.com.cn/statuses/update.json");
		mOAuthRequest.addBodyParam("source", mConsumerKey);
		mOAuthRequest.addBodyParam("status", params.get("status"));	
		mOAuthRequest.addOAuthParam("oauth_timestamp", getTimestampInSeconds());
		mOAuthRequest.addOAuthParam("oauth_nonce", getNonce());
		mOAuthRequest.addOAuthParam("oauth_consumer_key", mConsumerKey);
		mOAuthRequest.addOAuthParam("oauth_signature_method", "HMAC-SHA1");
		mOAuthRequest.addOAuthParam("oauth_version", "1.0");
	    mOAuthRequest.addOAuthParam("oauth_token", oAuthToken.getToken());
	    String str6 = getSignature(mOAuthRequest, oAuthToken);
	    mOAuthRequest.addOAuthParam("oauth_signature", str6);
		return mOAuthRequest.pushMsg();
	}
	@Override
	public String pushPicMsg(HashMap<String,String> params, OAuthToken oAuthToken){
		mOAuthRequest = new SinaOAuthRequest("POST", "http://api.t.sina.com.cn/statuses/upload.json");
		mOAuthRequest.addBodyParam("source", mConsumerKey);
		mOAuthRequest.addBodyParam("status", params.get("status"));	
		mOAuthRequest.addOAuthParam("oauth_timestamp", getTimestampInSeconds());
		mOAuthRequest.addOAuthParam("oauth_nonce", getNonce());
		mOAuthRequest.addOAuthParam("oauth_consumer_key", mConsumerKey);
		mOAuthRequest.addOAuthParam("oauth_signature_method", "HMAC-SHA1");
		mOAuthRequest.addOAuthParam("oauth_version", "1.0");
	    mOAuthRequest.addOAuthParam("oauth_token", oAuthToken.getToken());
	    String str6 = getSignature(mOAuthRequest, oAuthToken);
	    mOAuthRequest.addOAuthParam("oauth_signature", str6);
		return mOAuthRequest.pushMsg(params.get("pic"));
	}
	@Override
	public String getWeibo(HashMap<String, String> params, OAuthToken oAuthToken,int page) {
		mOAuthRequest = new SinaOAuthRequest("GET", "http://api.t.sina.com.cn/statuses/friends_timeline.json");
		mOAuthRequest.addBodyParam("source", mConsumerKey);
		mOAuthRequest.addBodyParam("page", page+"");
		mOAuthRequest.addBodyParam("count", MICROBOLGGING_DEFAULT_NUM+"");
		mOAuthRequest.addOAuthParam("oauth_timestamp", getTimestampInSeconds());
		mOAuthRequest.addOAuthParam("oauth_nonce", getNonce());
		mOAuthRequest.addOAuthParam("oauth_consumer_key", mConsumerKey);
		mOAuthRequest.addOAuthParam("oauth_signature_method", "HMAC-SHA1");
		mOAuthRequest.addOAuthParam("oauth_version", "1.0");
	    mOAuthRequest.addOAuthParam("oauth_token", oAuthToken.getToken());
	    String str6 = getSignature(mOAuthRequest, oAuthToken);
	    mOAuthRequest.addOAuthParam("oauth_signature", str6);
		return mOAuthRequest.getWeibo();
	}
	
	@Override
	public String getReView(HashMap<String, String> params,OAuthToken oAuthToken) {
		mOAuthRequest = new SinaOAuthRequest("GET", "http://api.t.sina.com.cn/statuses/comments.json");
		mOAuthRequest.addBodyParam("source", mConsumerKey);
		mOAuthRequest.addBodyParam("id", params.get("id"));	
		mOAuthRequest.addBodyParam("page", params.get("page"));
		mOAuthRequest.addBodyParam("count", COMMENT_DEFAULT_NUM+"");
		mOAuthRequest.addOAuthParam("oauth_timestamp", getTimestampInSeconds());
		mOAuthRequest.addOAuthParam("oauth_nonce", getNonce());
		mOAuthRequest.addOAuthParam("oauth_consumer_key", mConsumerKey);
		mOAuthRequest.addOAuthParam("oauth_signature_method", "HMAC-SHA1");
		mOAuthRequest.addOAuthParam("oauth_version", "1.0");
	    mOAuthRequest.addOAuthParam("oauth_token", oAuthToken.getToken());
	    String str6 = getSignature(mOAuthRequest, oAuthToken);
	    mOAuthRequest.addOAuthParam("oauth_signature", str6);
		return mOAuthRequest.getReview();
	}
	@Override
	public String sendReview(HashMap<String, String> params,
			OAuthToken oAuthToken) {
		mOAuthRequest = new SinaOAuthRequest("POST", "http://api.t.sina.com.cn/statuses/comment.json");
		mOAuthRequest.addBodyParam("source", mConsumerKey);
		mOAuthRequest.addBodyParam("id", params.get("id"));	
		mOAuthRequest.addBodyParam("comment", params.get("comment"));
		mOAuthRequest.addOAuthParam("oauth_timestamp", getTimestampInSeconds());
		mOAuthRequest.addOAuthParam("oauth_nonce", getNonce());
		mOAuthRequest.addOAuthParam("oauth_consumer_key", mConsumerKey);
		mOAuthRequest.addOAuthParam("oauth_signature_method", "HMAC-SHA1");
		mOAuthRequest.addOAuthParam("oauth_version", "1.0");
	    mOAuthRequest.addOAuthParam("oauth_token", oAuthToken.getToken());
	    String str6 = getSignature(mOAuthRequest, oAuthToken);
	    mOAuthRequest.addOAuthParam("oauth_signature", str6);
		return mOAuthRequest.sendReview();
	}
	
	@Override
	public String sendWeiboRepost(HashMap<String, String> params,
			OAuthToken oAuthToken) {
		mOAuthRequest = new SinaOAuthRequest("POST", "http://api.t.sina.com.cn/statuses/repost.json");
		mOAuthRequest.addBodyParam("source", mConsumerKey);
		mOAuthRequest.addBodyParam("id", params.get("id"));	
		mOAuthRequest.addBodyParam("status", params.get("status"));
		mOAuthRequest.addOAuthParam("oauth_timestamp", getTimestampInSeconds());
		mOAuthRequest.addOAuthParam("oauth_nonce", getNonce());
		mOAuthRequest.addOAuthParam("oauth_consumer_key", mConsumerKey);
		mOAuthRequest.addOAuthParam("oauth_signature_method", "HMAC-SHA1");
		mOAuthRequest.addOAuthParam("oauth_version", "1.0");
	    mOAuthRequest.addOAuthParam("oauth_token", oAuthToken.getToken());
	    String str6 = getSignature(mOAuthRequest, oAuthToken);
	    mOAuthRequest.addOAuthParam("oauth_signature", str6);
		return mOAuthRequest.sendWeiboRepost();
	}
	@Override
	public String getUserData(OAuthToken oAuthToken) {
		mOAuthRequest = new SinaOAuthRequest("GET", "http://api.t.sina.com.cn/users/show.json");
		mOAuthRequest.addBodyParam("source", mConsumerKey);
		mOAuthRequest.addBodyParam("user_id", oAuthToken.getUserid());	
		mOAuthRequest.addOAuthParam("oauth_timestamp", getTimestampInSeconds());
		mOAuthRequest.addOAuthParam("oauth_nonce", getNonce());
		mOAuthRequest.addOAuthParam("oauth_consumer_key", mConsumerKey);
		mOAuthRequest.addOAuthParam("oauth_signature_method", "HMAC-SHA1");
		mOAuthRequest.addOAuthParam("oauth_version", "1.0");
	    mOAuthRequest.addOAuthParam("oauth_token", oAuthToken.getToken());
	    OAuthToken mOAuthToken = new OAuthToken(oAuthToken.getToken(), oAuthToken.getSecret());
	    String str6 = getSignature(mOAuthRequest, mOAuthToken);
	    mOAuthRequest.addOAuthParam("oauth_signature", str6);
		return mOAuthRequest.getUserData();
	}
}
